<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>个人主页</title>

		<meta name="viewport" content="initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<!-- 引入css文件 -->
		<link rel="stylesheet" href="../css/sm.min.css">
		<link rel="stylesheet" href="../css/sm-extend.min.css">
		<link rel="stylesheet" href="../css/iconfont.css">
		<style type="text/css">
			#index {
				margin-top: 0.4rem;
			}
			.infinite-scroll-preloader {
				margin-top: -20px;
			}
			/* 卡片内容加边距 */
			.my-cont{
				padding:.2rem .99rem;
				text-align:center
				
			}
			/* 背景色白色 */
			.page, .page-group{
				background-color: white;
			}
			/* 去掉卡片边距 */
			.facebook-card{
				margin: 0;
			}
			.card-content{
				/* margin-top: 0.625rem; */
			}
			/* 用户字体 */
			.list-block .my-user{
				font-size :0.6rem;
				color:rgb(150,150,150);
			}
			/* 头像圆角 */
			.my-photo img{
				border-radius: 1rem;
			}
			/*商品*/
			.commodity-title{
				font-weight: bold;
				font-size: medium;
			}
			.commodity-price{
				font-weight: bold;
				color: red;
				padding-right: 5rem;
				font-size: medium;
			}
			/* 用户 */
			.user-name{
				font-size :0.6rem;
				color:gray;
			}
			.leavemessage{
				font-size :0.6rem;
			}
			.link{
				font-size :0.6875rem;
				font-weight: bold;
			}
			.name{
				padding-left: 4rem;
			}
			.nickname{
				padding-left: 4rem;
				font-size :small;
			}
			.info{
				color: white;
				padding-left: 1.25rem;
				font-size :medium;
				font-weight: bold;
			}
			/* 跳转连接颜色 */
			a{
				color: inherit;
			}
			a:active{
				color: inherit;
			}
		</style>
		<style type="text/css">
			.infinite-scroll-preloader {
				margin-top: -20px;
			}
		</style>
	</head>
	<body>
		<div id="app">
			<!-- page 容器 -->
			<div class="page" >
				<!-- 这里是页面内容区 -->
				<div class="content" v-if="loginuser">
					<!-- 顶部用户信息 -->
					<div class="card facebook-card" style="background-color: #C2BE9E;">
						<a class="icon icon-left" @click="goBack" style="color: white;"></a>
					    <div class="card-header no-border">
							<div class="facebook-avatar">
							  <img :src="imgSrc(loginuser.photo)" width="58" height="50">
							</div>
					      <div class="name" style="color: white;">{{loginuser.name}}</div>
					      <div class="nickname " style="color: white;">昵称：{{loginuser.nickname}}</div>
						  <div class="attention">
						  	<button class="button pull-right open-popup" data-popup=".popup-about"
						  	style="background-color: #C2BE9E;color: #FAF2CC;border-color:white;">
						  		查看地址
						  	</button>
						  </div>
					    </div>
						<span class="Introduction" style="color: white;">
							{{loginuser.intro}}<br/>
						</span>
						<div >
							<a href="#" @click="goMyAttention" class="info">关注</a>
							<a href="#" @click="goMyFans" class="info">粉丝</a>
						</div>
					</div>
					<!-- 标题栏 -->
					<div class="buttons-tab">
					    <a href="#tab1" class="tab-link active button">我的</a>
					    <a href="#tab2" class="tab-link button">评价</a>
					</div>
					<!-- 主内容 -->
					<div class="content-block">
						<div class="tabs">
							<!-- 发布页 -->
						  <div id="tab1" class="tab active">
							<div class="list-block">
								<div class="list-block media-list" v-for="commodity in mycommodities">
									<ul>
									  <li>
										<a @click="goCommodity(commodity.id)" class="item-link item-content">
										  <div class="item-media">
											  <img :src="imgSrc(commodity.picture)" style='width: 5rem;'>
											 </div>
										  <div class="item-inner">
											<div class="item-title-row">
											  <div class="item-title">
												  <span class="commodity-title">
													{{commodity.title}}<br/>
												  </span>
											  </div>
											</div>
											<div class="item-subtitle" style="padding-top:10px">
												<span class="commodity-price">
													￥{{commodity.price}}
												</span>
											</div>
											<template v-if="commodity.status==1">
												<div style="background-color: gainsboro;text-align: center;">
													<span>卖掉了</span>
												</div>
											</template>
										  </div>
										</a>
									  </li>
									</ul>
								</div>	
							</div>
						  </div>
						  <!-- 评价页 -->
						  <div id="tab2" class="tab">
							<div class="list-block">
								<div class="card facebook-card addleave-message">
									<div class="card-header " v-for="appraise in myappraises">
									  <div class="facebook-avatar">
										  <img :src="imgSrc(appraise.senduser.photo)" width="40" height="40">
										</div>
									  <div class="facebook-name">{{appraise.senduser.nickname}}</div>
									  <div class="facebook-date" >{{appraise.date}}</div>
									  <div>
										<span class="leavemessage">
											{{appraise.appraise}}<br/>
										</span>
									  </div>
									</div>
								</div>
							</div>
						  </div>
						</div>
					</div>
				</div>
			</div>
			<!-- About Popup -->
			<div class="popup popup-about">
			  <div class="content-block">
			    <p><a href="#" class="close-popup">返回页面</a></p>
			    <div class='card' v-for="address in allAddress">
			    	<div class='card-header'>
						{{address.name}} {{address.phone}}
			    	</div>
			    	<div class='card-content'>
			    		<div class='card-content-inner'>
							{{address.shopAddress.country}}{{address.shopAddress.province}}{{address.shopAddress.city}}{{address.shopAddress.detail}}
			    		</div>
			    	</div>
			    	<div class='card-footer'>
						<a href='#'>
							更换
						</a>
					</div>
			    </div>
				<button class="button pull-right" @click="goAddAdress"
				style="background-color: #C2BE9E;color: #FAF2CC;border-color:#C2BE9E;">
					新增地址
				</button>
			  </div>
			</div>
		</div>
		<script src='../js/jquery-3.2.1.min.js'></script>
		<script src='../js/sm.js'></script>
		<script src='../js/sm-extend.js'></script>
		<script src='../js/vue.js'></script>
		<script src='../js/axios.min.js'></script>
		<script src="../js/config.js"></script>
		
		<script type="text/javascript">
			//获取url中的参数
			function getUrlParam(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
			var r = window.location.search.substr(1).match(reg); //匹配目标参数
			if (r != null) return unescape(r[2]); return null; //返回参数值
			 }
		</script>
		
		<script>
			//获取URL参数
			var loginuserid = getUrlParam('loginuserid');
			
			//VUE
			var app = new Vue({
				el:"#app",
				data:{
					loginuser:null,
					mycommodities:[],
					myappraises:[],
					allAddress:[]
				},
				created() {
					//初始化加载用户信息
					this.inituser();
					//初始化加载商品数据
					this.initmycommodities();
					//初始加载评价
					this.initmyappraises();
				},
				// 方法
				methods:{
					inituser: function() {
						axios.get(serviceIP+"/market/inituser?userid=" + loginuserid,{
							headers:{"token":token,"refreshtoken":refreshtoken}
						}).then(result => {
							this.loginuser = result.data.data;
							//初始加载所有地址
							this.initalladdress();
						});
					},
					initmycommodities: function() {
						axios.get(serviceIP+"/market/initusercommodities?userid=" + loginuserid,{
							headers:{"token":token,"refreshtoken":refreshtoken}
						}).then(result => {
							this.mycommodities = result.data.data;
						});
					},
					initmyappraises: function() {
						axios.get(serviceIP+"/market/inituserappraise?userid=" + loginuserid,{
							headers:{"token":token,"refreshtoken":refreshtoken}
						}).then(result => {
							this.myappraises = result.data.data;
							//alert(result.data.code);
						});
					},
					initalladdress: function() {
						axios.get(serviceIP+"/market/initalladdress?userId=" + loginuserid,{
							headers:{"token":token,"refreshtoken":refreshtoken}
						}).then(result => {
							this.allAddress = result.data.data;
						});
					},
					
					//跳转到商品页面
					goCommodity:function(id){
						window.location="market-commodity.html?commodityid="+id
					},
					//跳转上层打开页面
					goBack:function(){
						window.history.go(-1)
					},
					//图片映射
					imgSrc: function(src) {
						return src;
					},
					//关注页面跳转
					goMyAttention:function(){
						window.location="market-myattention.html?loginuserid="+this.loginuser.id
					},
					//粉丝页面跳转
					goMyFans:function(){
						window.location="market-myfans.html?loginuserid="+this.loginuser.id
					},
					goAddAdress:function(){
						window.location="market-addaddress.html?loginuserid="+this.loginuser.id
					},
					
				},
			});
		</script>
		
		<script>
			$.init();
		</script>
	</body>

</html>
